﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SF.Utilities;
using SF.Import;
using System.Data;

namespace SF.Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            ////typeof(UserState); 就是java的 .class
            ////跟java写法一样，实在要说复杂，就是多了一个 强转（UserState）
            //UserState us = (UserState)Enum.Parse(typeof(UserState), "Normal");

            ////从语法角度来说，我也认为Enum.Parse应该支持泛型，这点略有欠缺（不知道为什么不实现。。但实现真的很容易），所以我这样写扩展：
            //UserState us2 = EnumExt.Parse<UserState>("Normal"); //这样就和java的写法一样了

            //Console.WriteLine(us.ToString());


            int? a = 1;
            Nullable<int> b = 2;
            int c = 3;
            int? d = null;

            Type t1 = a.GetType(), t2 = b.GetType(), t3 = c.GetType();
            Console.WriteLine(t1.FullName);
            Console.WriteLine(t2.FullName);
            Console.WriteLine(t3.FullName);
            Console.WriteLine(t1 == t2);
            Console.WriteLine(t2 == t3);
            Console.WriteLine(t1 == t3);
            Console.WriteLine(typeof(int).FullName);
            Console.WriteLine(typeof(int?).FullName);

        }

        [TestMethod]
        public void test2()
        {
            string path = "C:\\Users\\溪林\\Desktop\\测试1.xls";

            FileInfo file = new FileInfo(path);

            Console.WriteLine(file == null ? 0 : 1);

            var data = NPOIImport.GetExcelData(file, true);
            foreach (var item in data)
            {
                Console.WriteLine("sheet名：" + item.Key);
                Console.WriteLine("内如如下：");
                int index = 1;
                foreach (var item2 in item.Value)
                {
                    Console.WriteLine("第" + index + "行：");
                    foreach (var item3 in item2)
                    {
                        Console.WriteLine("列名：" + item3.Key + "，列值：" + item3.Value + "。");
                    }
                    index++;
                }
            }
        }

        [TestMethod]
        public void test3()
        {
            string path = "C:\\Users\\溪林\\Desktop\\测试2.xlsx";

            FileInfo file = new FileInfo(path);

            Console.WriteLine(file == null ? 0 : 1);

            var data = NPOIImport.test1(file);
            foreach (DataTable item in data.Tables)
            {
                Console.WriteLine("sheet名：" + item.TableName);
                Console.WriteLine("数据如下：");
                int index = 1;
                foreach (DataRow item2 in item.Rows)
                {
                    Console.WriteLine("第" + index + "行：");
                    foreach (DataColumn item3 in item.Columns)
                    {
                        string value = item2[item3.ColumnName].ToString();
                        Console.WriteLine("列名：[" + item3.ColumnName + "]，列值：[" + value + "]，长度-" + value.Length);
                    }
                    index++;
                }
            }
        }
    }
}
